﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ZK.Common;

namespace ZK.Common
{
    public partial class WebApiService
    {
        private static readonly string CsCN = "cs/";
        private static readonly string AutoControlTransportCN = "autoControlTransport/";
        // private static readonly string UpdateHardWareByNameAN = CsCN + "updateHardWareByName";//根据硬件名称修改硬件状态
        private static readonly string AddHardWareLogAN = CsCN + "addHardWareLog";//根据硬件名称修改硬件状态
        private static readonly string TruckWeightBillAN = AutoControlTransportCN + "truckWeightBill";//生成磅单接口
        private static readonly string EndYxInfoAN = AutoControlTransportCN + "endYxInfo";//结束运销流程
        private static readonly string GetTheLatestAN = AutoControlTransportCN + "getTheLatest";//获取最后磅单信息接口




        /// <summary>
        /// 获取最后磅单信息接口
        /// </summary>
        /// <param name="cardNo"></param>
        /// <returns></returns>
        public static ReceiveDataBase<YxYsTransportReturnDto> GetTheLatest(string cardNo)
        {
            Dictionary<string, string> keyValuePairs = new Dictionary<string, string>();
            keyValuePairs.Add("cardNo", cardNo);
            string url = InterfaceExecute.GetUrl(GetTheLatestAN, keyValuePairs);
            string ret;
            try
            {
                ret = HttpClientUtil.doGetMethodToString(url);
            }
            catch (Exception ex)
            {
                Common.Log4.LogManage.WriteErr("GetTheLatest " + ex.ToString());
                return null;
            }
            return Newtonsoft.Json.JsonConvert.DeserializeObject<ReceiveDataBase<YxYsTransportReturnDto>>(ret);

        }

        /// <summary>
        /// 结束运销流程
        /// </summary>
        /// <param name="cardNo"></param>
        /// <returns></returns>
        public static ReceiveDataBase<int?> EndYxInfo(string cardNo)
        {
            Dictionary<string, string> keyValuePairs = new Dictionary<string, string>();
            keyValuePairs.Add("cardNo", cardNo);
            string url = InterfaceExecute.GetUrl(EndYxInfoAN, keyValuePairs);
            string ret;
            try
            {
                ret = HttpClientUtil.doGetMethodToString(url);
            }
            catch (Exception ex)
            {
                Common.Log4.LogManage.WriteErr("EndYxInfo " + ex.ToString());
                return null;
            }
            return Newtonsoft.Json.JsonConvert.DeserializeObject<ReceiveDataBase<int?>>(ret);

        }
        /// <summary>
        /// 生成磅单接口
        /// </summary>
        /// <param name="weightBillDtoSendM"></param>
        /// <returns></returns>
        public static ReceiveDataBase<int?> TruckWeightBill(WeightBillDtoSendM weightBillDtoSendM)
        {
            string url = InterfaceExecute.GetUrl(TruckWeightBillAN);
            string ret;
            try
            {
                ret = HttpClientUtil.doPostMethodToString(url, Newtonsoft.Json.JsonConvert.SerializeObject(weightBillDtoSendM));
            }
            catch (Exception ex)
            {
                Common.Log4.LogManage.WriteErr("TruckWeightBill " + ex.ToString());
                return null;
            }
            return Newtonsoft.Json.JsonConvert.DeserializeObject<ReceiveDataBase<int?>>(ret);

        }
        /// <summary>
        /// 添加硬件异常信息
        /// </summary>
        /// <param name="wareName"></param>
        /// <param name="wareState"></param>
        /// <param name="remark"></param>
        public static void AddHardWareLog(string wareName, int wareState, string remark)
        {
            var m = new { wareName = wareName, wareState = wareState, remark = remark };
            string ret;
            string url = InterfaceExecute.GetUrl(AddHardWareLogAN);
            try
            {
                ret = HttpClientUtil.doPostMethodToString(url, Newtonsoft.Json.JsonConvert.SerializeObject(m));
            }
            catch (Exception ex)
            {
                Common.Log4.LogManage.WriteErr("AddHardWareLog " + ex.Message);
            }
        }

        /// <summary>
        /// 根据硬件名称修改硬件状态
        /// </summary>
        /// <param name="wareName"></param>
        /// <param name="wareState"></param>
        /// <param name="remark"></param>
        /// <returns></returns>
        //public static void UpdateHardWareByName(string wareName, int wareState, string remark)
        //{
        //    string ret;
        //    Dictionary<string, string> keyValuePairs = new Dictionary<string, string>();
        //    keyValuePairs.Add("wareName", wareName);
        //    keyValuePairs.Add("wareState", wareState.ToString());
        //    keyValuePairs.Add("remark", remark);
        //    string url = InterfaceExecute.GetUrl(UpdateHardWareByNameAN, keyValuePairs);
        //    try
        //    {
        //        ret = HttpClientUtil.doPostMethodToString(url);
        //    }
        //    catch (Exception ex)
        //    {
        //        Common.Log4.LogManage.WriteErr(ex.Message);
        //    }

        //}

    }
}
